<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>X-Admin CRUD 生成器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            overflow: hidden;
        }

        .header {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
        }

        .header p {
            opacity: 0.9;
            font-size: 1.1rem;
        }

        .form-container {
            padding: 40px;
        }

        .form-section {
            margin-bottom: 40px;
        }

        .section-title {
            font-size: 1.5rem;
            color: #374151;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid #e5e7eb;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #374151;
        }

        input, select, textarea {
            width: 100%;
            padding: 12px;
            border: 2px solid #e5e7eb;
            border-radius: 8px;
            font-size: 14px;
            transition: border-color 0.3s;
        }

        input:focus, select:focus, textarea:focus {
            outline: none;
            border-color: #4f46e5;
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
        }

        .fields-container {
            border: 2px solid #e5e7eb;
            border-radius: 8px;
            padding: 20px;
            background: #f9fafb;
        }

        .field-item {
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 15px;
            position: relative;
        }

        .field-header {
            display: flex;
            justify-content: between;
            align-items: center;
            margin-bottom: 15px;
        }

        .field-title {
            font-weight: 600;
            color: #374151;
        }

        .remove-field {
            background: #ef4444;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 12px;
        }

        .remove-field:hover {
            background: #dc2626;
        }

        .field-grid {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 15px;
        }

        .field-options {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 10px;
            margin-top: 15px;
        }

        .checkbox-group {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .checkbox-group input[type="checkbox"] {
            width: auto;
        }

        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
        }

        .btn-primary {
            background: #4f46e5;
            color: white;
        }

        .btn-primary:hover {
            background: #4338ca;
            transform: translateY(-2px);
        }

        .btn-secondary {
            background: #6b7280;
            color: white;
        }

        .btn-secondary:hover {
            background: #4b5563;
        }

        .btn-success {
            background: #10b981;
            color: white;
        }

        .btn-success:hover {
            background: #059669;
        }

        .actions {
            display: flex;
            gap: 15px;
            justify-content: center;
            margin-top: 40px;
            padding-top: 30px;
            border-top: 2px solid #e5e7eb;
        }

        .preview {
            background: #f3f4f6;
            border: 1px solid #d1d5db;
            border-radius: 8px;
            padding: 20px;
            margin-top: 20px;
        }

        .preview h3 {
            margin-bottom: 15px;
            color: #374151;
        }

        .preview pre {
            background: #1f2937;
            color: #f9fafb;
            padding: 15px;
            border-radius: 6px;
            overflow-x: auto;
            font-size: 13px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🚀 X-Admin CRUD 生成器</h1>
            <p>可视化配置界面 - 轻松创建完整的CRUD模块</p>
        </div>

        <div class="form-container">
            <form id="crudForm">
                <!-- 基本信息 -->
                <div class="form-section">
                    <h2 class="section-title">📋 基本信息</h2>
                    <div class="form-row">
                        <div class="form-group">
                            <label for="modelName">模型名称 *</label>
                            <input type="text" id="modelName" name="modelName" placeholder="例如: Product" required>
                        </div>
                        <div class="form-group">
                            <label for="tableName">表名 *</label>
                            <input type="text" id="tableName" name="tableName" placeholder="例如: products" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="comment">模块描述</label>
                        <input type="text" id="comment" name="comment" placeholder="例如: 商品管理">
                    </div>
                </div>

                <!-- 字段配置 -->
                <div class="form-section">
                    <h2 class="section-title">🔧 字段配置</h2>
                    <div class="fields-container">
                        <div id="fieldsContainer">
                            <!-- 字段将动态添加到这里 -->
                        </div>
                        <div style="margin-top: 15px; display: flex; gap: 10px; flex-wrap: wrap;">
                            <button type="button" class="btn btn-secondary" onclick="addField()">+ 添加字段</button>
                            <button type="button" class="btn btn-secondary" onclick="addPresetField('name')">+ 名称字段</button>
                            <button type="button" class="btn btn-secondary" onclick="addPresetField('status')">+ 状态字段</button>
                            <button type="button" class="btn btn-secondary" onclick="addPresetField('sort')">+ 排序字段</button>
                            <button type="button" class="btn btn-secondary" onclick="addPresetField('description')">+ 描述字段</button>
                        </div>
                    </div>
                </div>

                <!-- 数据库导入 -->
                <div class="form-section">
                    <h2 class="section-title">🗄️ 数据库导入</h2>
                    <div class="form-row">
                        <div class="form-group">
                            <label for="dbTable">数据库表名</label>
                            <input type="text" id="dbTable" placeholder="输入表名，例如: users">
                        </div>
                        <div class="form-group" style="display: flex; align-items: end;">
                            <button type="button" class="btn btn-secondary" onclick="importFromDatabase()" style="width: 100%;">📥 从数据库导入</button>
                        </div>
                    </div>
                </div>

                <!-- 操作按钮 -->
                <div class="actions">
                    <button type="button" class="btn btn-secondary" onclick="previewConfig()">👀 预览配置</button>
                    <button type="button" class="btn btn-primary" onclick="generateCode()">🎯 生成代码</button>
                    <button type="button" class="btn btn-success" onclick="saveConfig()">💾 保存配置</button>
                    <button type="button" class="btn btn-secondary" onclick="loadExistingConfig()">📂 加载已有配置</button>
                </div>
            </form>

            <!-- 预览区域 -->
            <div id="previewSection" class="preview" style="display: none;">
                <h3>📄 配置预览</h3>
                <pre id="previewContent"></pre>
            </div>
        </div>
    </div>

    <script src="app.js"></script>
</body>
</html>
